import Vue from 'vue'
import Vuex from 'vuex'
import { getLocal } from '@/utils/local.js'
import { getUserInfo } from '@/api/login.js'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    userInfo: JSON.parse(getLocal('userInfo')) || {}
  },
  mutations: {
    setUserInfo (state, Payload) {
      state.userInfo = Payload
    }
  },
  actions: {
    async setUserInfo (context) {
      const res = await getUserInfo()
      context.commit('setUserInfo', res.data.data)
    }
  },
  modules: {}
})
